package com.ygsoft.activiti.identity;

import org.activiti.engine.IdentityService;
import org.activiti.engine.identity.Group;
import org.activiti.engine.identity.User;
import org.activiti.engine.impl.persistence.entity.GroupEntity;
import org.activiti.engine.impl.persistence.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 内部实现的 操作activiti的保存类
 *
 * @author zhx
 * @create 2017-11-13 9:51
 **/
@Component
public class AbsoluteIdentityServiceImpl implements IdentityServiceInf{

    @Autowired
    private IdentityService identityService;

    @Override
    public boolean saveUser(String userId,String userName,String email) {
        // 实例化用户实体
        User user=new UserEntity();
        user.setId(userId);
        user.setEmail(email);
        user.setFirstName(userName);
        user.setLastName(userName);

        identityService.saveUser(user);
        return true;
    }

    @Override
    public boolean deleteUser(String userId) {
        identityService.deleteUser(userId);
        return true;
    }

    @Override
    public boolean saveGroup(String groupId,String groupName) {
        // 实例化组实体
        Group group=new GroupEntity();
        group.setId(groupId);
        group.setName(groupName);

        return true;
    }

    @Override
    public boolean deleteGroup(String groupId) {
        identityService.deleteGroup(groupId);
        return true;
    }

    @Override
    public boolean createMembership(String userId,String groupId) {
        identityService.createMembership(userId,groupId);
        return true;
    }

    @Override
    public boolean deleteMembership(String userId,String groupId) {
        identityService.deleteMembership(userId,groupId);
        return true;
    }
}
